package com.prs.crm.service.oa.impl;

import java.io.File;
import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.AppContext;
import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.oa.SynodDao;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.Notice;
import com.prs.crm.domain.oa.Synod;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.oa.NoticeService;
import com.prs.crm.service.oa.SynodService;

public class SynodServiceImpl extends BaseServiceImpl<Synod,SynodDao> implements SynodService{
	private PersonService personService;
	private NoticeService noticeService;
	
	@Override
	public void saveSynod(Synod synod, File file, String fileName,String joinPersons) {
		// TODO Auto-generated method stub
		Attach attach = FileUtil.getInstance().saveFile(file, fileName, "", Constrains.UPLOAD_DIR_SYNOD);
		if(attach.getSrc() != null) {
			synod.setAttach(attach.getSrc());
		}
		Collection<Person> persons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(joinPersons.split(",")));
		synod.addJoinPersons(persons);
		synod.setRecordTime(new Date());
		synod.setRecorder(AppContext.getAccountContext().currentUser());
		this.getDao().save(synod);
		
		for(Person person : persons) {
			String msg = "会议:"+synod.getTitle()+"已安排，请准时参加";
			Notice notice = new Notice();
			notice.setTitle("参加会议");
			notice.setContent(msg);
			
			this.getNoticeService().sendNotice(notice, person);
		}
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	public PersonService getPersonService() {
		return personService;
	}
	@Override
	public Collection<Synod> getSynod(Person person, Date date) {
		// TODO Auto-generated method stub
		return this.getDao().getSynod(person, date);
	}
	public void setNoticeService(NoticeService noticeService) {
		this.noticeService = noticeService;
	}
	public NoticeService getNoticeService() {
		return noticeService;
	}

}
